classdef dotsDrawableImage < dotsDrawable
    % @class dotsDrawableImage
    % Draw an image from a file.
    %
    % @ingroup drawable
    
    properties (SetObservable = true)
        % string name of an image file to display
        fileName;
    end
    
    methods
        % Constructor takes no arguments.
        function self = dotsDrawableImage
            self = self@dotsDrawable;
        end
        
        % Draw the image with the Psychtoolbox Screen PutImage.
        function draw(self)
            if ~isempty(self.fileName)
                fileWithPath = fullfile(self.imagesPath, self.fileName);
                [filePath, fileName, fileType] = fileparts(fileWithPath);
                
                % get image array with Matlab's builtin imread
                imageArray = imread(fileWithPath);
                
                % draw image array
                Screen('PutImage', ...
                    self.windowNumber, ...
                    imageArray, ...
                    self.windowRect);
            end
        end
    end
end